<template>
  <fieldset>
    <legend>评论</legend>
    <div class="get">
      <p v-for="item in it" :key="item.id">
        {{ item.content }} <span>{{ item.name }}</span>
        <button @click="del(item)">删除</button>
      </p>
    </div>
    <div>
      <textarea v-model="ipt"></textarea>
      <button @click="send">发表评论</button>
    </div>
  </fieldset>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      ipt: "",
      it: [],
    };
  },
  methods: {
    send() {
      if (this.ipt !== "") {
        let str = prompt("请输入您的昵称");
        if (str !== "") {
          axios
            .post(
              "http://chst.vip:1902/students/addlist",
              {
                content: this.ipt,
                name: str,
              },
              {
                headers: {
                  qf: "1agbuni",
                },
              }
            )
            .then((res) => {
              console.log(res);
            })
            .catch((err) => {
              console.log(err);
            });
        }
      }
    },
    del(i) {
      console.log(i.id);
      axios
        .get("http://chst.vip:1902/students/del", {
          params: {
            id: i.id,
          },
          header: {
            af: "1wfbvbenine",
          },
        })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  // computed: {
  //   lun() {
  //     console.log(this.it);
  //     return axios
  //       .get("http://chst.vip:1902/students/getstulist", {
  //         params: {},
  //         header: {
  //           qf: "12csbvjbsc",
  //         },
  //       })
  //       .then((res) => {
  //         console.log(res);
  //         this.it = res.data.data;
  //       });
  //   },
  // },
};
</script>
<style scoped>
.get {
  width: 500px;
  height: 500px;
  background-color: skyblue;
}
</style>
